home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#44 (May 89)
/
Cursor Stuff
/
main.c
< prev
next >
Wrap
Text File
|
1989-02-17
|
4KB
|
93 lines
/* Animated Cursor demonstration main program.
Copyright © 1989 by Michael S. Morton, all rights reserved.
Written February ’89 for MacTutor.
*/
#include "AnimCurs.h" /* define functions in package */
/* Internal prototypes: */
void main (void);
void makeMenus (void);
void doMenu (long result);
int theDelay = 4; /* delay between animation frames, tix */
enum /* items in our sole menu */
{ mnWatch = 1, mnWatch2, mnHourG, mnUnused1,
mnFaster, mnSlower, mnTop, mnUnused2, mnQuit };
void main ()
{ EventRecord evtRec; /* info from GetNextEvent () */
int inWhat; /* from FindWindow (): where was click? */
WindowPtr theWin; /* unused -- just for FindWindow () */
long menuResult; /* from MenuKey () or MenuSelect () */
/* The usual initializations: perhaps more than we need here. */
InitGraf (&thePort); /* initialize QuickDraw */
InitFonts (); /* init the Font Manager */
FlushEvents (everyEvent, 0); /* ignore pending events */
InitWindows (); /* init the Window Manager */
InitMenus (); /* init the Menu Manager */
TEInit (); /* init TextEdit */
InitDialogs (0L); /* init Dialog Mgr; no restart proc */
InitCursor (); /* show standard arrow cursor */
makeMenus (); /* set up one cheap little menu */
acStartW1 (theDelay); /* initialize to a one-handed watch */
/* Main loop: at idle time, update the cursor. Check for menu commands
via the mouse or keyboard. */
while (1)
{ acNext (); /* idle time: animate the cursor */
SystemTask (); /* can’t hurt, altho we don’t do DAs */
if (GetNextEvent (everyEvent, & evtRec)) /* try for an event */
{ if (evtRec.what == mouseDown) /* click? */
{ inWhat = FindWindow (evtRec.where, &theWin); /* look up where it hit */
if (inWhat == inMenuBar) /* menu click? */
doMenu (MenuSelect(& (evtRec.where))); /* track & process menu hit */
else SysBeep (2); /* can’t handle clicks elsewhere */
} /* end of handling mouseDown */
else if (evtRec.what = keyDown) /* keypress? */
doMenu (MenuKey((char) evtRec.message)); /* don’t require cmdKey */
} /* end of handling one event */
} /* end of infinite loop */
} /* end of main () */
/* Make menu in-line. (Resources? This is just a demo driver…) */
void makeMenus ()
{ MenuHandle theMenu; /* our sole menu */
theMenu = NewMenu (1, "\pMenu");
AppendMenu (theMenu, "\pWatch/W;Two-handed watch/2;Hourglass/H;(-");
AppendMenu (theMenu, "\pFaster/F;Slower/S;Top speed/T;(-");
AppendMenu (theMenu, "\pQuit/Q;(-");
AppendMenu (theMenu, "\pAnimated Cursor Demo;written in LightspeedC");
AppendMenu (theMenu, "\pCopyright © 1989;Michael S. Morton;for MacTutor");
InsertMenu (theMenu, 0); /* put it in the menu bar */
DrawMenuBar (); /* show our handiwork */
} /* end of makeMenus () */
void doMenu (result)
long result; /* INPUT: result from MenuSelect/Key */
{ int command = LoWord (result); /* extract item number */
switch (command)
{ case mnWatch: acStartW1 (theDelay); break;
case mnWatch2: acStartW2 (theDelay); break;
case mnHourG: acStartHG (theDelay); break;
/* Note that we can’t let the delay go down to zero for “Faster”. */
case mnFaster: if (theDelay>1) --theDelay; acDelay (theDelay); break;
case mnSlower: ++theDelay; acDelay (theDelay); break;
case mnTop: theDelay = 1; acDelay (theDelay); break;
case mnQuit: ExitToShell (); break;
default: break; /* ignore unrecognized items */
} /* end of switch on command */
HiliteMenu (0);
} /* end of doMenu () */